package com.leetcode.algorithm.y22.m08.w2;

/**
 * 1413. 逐步求和得到正数的最小值
 * 
 * https://leetcode.cn/problems/minimum-value-to-get-positive-step-by-step-sum/
 * 
 * @author jie.deng
 *
 */
class Question1413Solution01 {

	public int minStartValue(int[] nums) {
		int minSum = Integer.MAX_VALUE;
		int sum = 0;
		for (int i = 0; i < nums.length; i++) {
			sum += nums[i];
			if (sum < minSum) {
				minSum = sum;
			}
		}
		if (minSum >= 1) {
			return 1;
		}
		return 1 - minSum;
	}

}